/*
 * @Author: zhengzhuang
 * @Date: 2020-08-28 11:34:40
 * @LastEditors: zhengzhuang
 * @LastEditTime: 2020-11-18 09:21:28
 * @Description: In User Settings Edit
 * @FilePath: /C20Driver/lib/pages/user_module/modify_nickname.dart
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:C20Driver/provider/driver_information.dart';
import 'package:C20Driver/service/request.dart';
import 'package:provider/provider.dart';

/// 修改昵称
class ModifyNickname extends StatefulWidget {
  @override
  _ModifyNicknameState createState() => _ModifyNicknameState();
}

class _ModifyNicknameState extends State<ModifyNickname> {
  TextEditingController controller = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('修改昵称'),
      ),
      body: Container(
        padding: EdgeInsets.only(
          left: ScreenUtil().setWidth(30.0),
          right: ScreenUtil().setWidth(30.0),
        ),
        child: Consumer<DriverInformation>(builder: (context, model, child) {
          controller.text = model.driverInfo.driverName;
          return Column(
            children: <Widget>[
              SizedBox(height: ScreenUtil().setWidth(50.0)),
              TextField(
                controller: controller,
                decoration: InputDecoration(
                  hintText: '用户昵称',
                  contentPadding: EdgeInsets.all(10.0),
                ),
              ),
              SizedBox(height: ScreenUtil().setWidth(50.0)),
              MaterialButton(
                child: Text('修改',
                    style: TextStyle(
                        fontSize: ScreenUtil().setSp(34.0),
                        color: Colors.white)),
                minWidth: ScreenUtil().setWidth(690.0),
                height: ScreenUtil().setWidth(88.0),
                color: Color.fromARGB(255, 255, 153, 0),
                onPressed: () =>
                    Request.updateDriverName(context, controller.text),
              ),
            ],
          );
        }),
      ),
    );
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }
}
